;;==========================================================================
;; Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
;;==========================================================================

    AREA |.text|,ALIGN=2,CODE, READONLY

;
;   void StubInvokeMethod1(
;       ECode *pHR, UInt32 *puArgs, UInt32 uMethodAddr, UInt32 regs[8])
;
    EXPORT  StubInvokeMethod1

StubInvokeMethod1
    str     r4, [r3, #0]
    mov     r4, r3
    str     r0, [r4, #4]
    str     r1, [r4, #8]
    str     r2, [r4, #12]
    str     r3, [r4, #16]
    str     ip, [r4, #20]
    str     lr, [r4, #24]
    str     sp, [r4, #28]

    // TODO: assert the state of the stack:sp == r1
    mov     ip, r2
    mov     sp, r1
    ldr     r0, [sp]
    ldr     r1, [sp, #4]
    ldr     r2, [sp, #8]
    ldr     r3, [sp, #12]
    adr     lr, __StubInvokeNext1
    mov     pc, ip

__StubInvokeNext1

    ldr     r1, [r4, #4]
    str     r0, [r1]

    ldr     sp, [r4, #28]
    ldr     lr, [r4, #24]
    ldr     ip, [r4, #20]
    ldr     r3, [r4, #16]
    ldr     r2, [r4, #12]
    ldr     r1, [r4, #8]
    ldr     r0, [r4, #4]
    ldr     r4, [r4, #0]

    mov     pc, lr

;
;   void StubInvokeMethod2(
;       ECode *pHR, UInt32 *puArgs, UInt32 uMethodAddr, UInt32 regs[8])
;
    EXPORT  StubInvokeMethod2

StubInvokeMethod2
    str     r4, [r3, #0]
    mov     r4, r3
    str     r0, [r4, #4]
    str     r1, [r4, #8]
    str     r2, [r4, #12]
    str     r3, [r4, #16]
    str     ip, [r4, #20]
    str     lr, [r4, #24]
    str     sp, [r4, #28]

    // TODO: assert the state of the stack
    mov     ip, r2
    mov     sp, r1
    ldr     r0, [sp]
    ldr     r1, [sp, #4]
    ldr     r2, [sp, #8]
    ldr     r3, [sp, #12]
    add     sp, sp, #16
    adr     lr, __StubInvokeNext2
    mov     pc, ip

__StubInvokeNext2

    ldr     r1, [r4, #4]
    str     r0, [r1]

    ldr     sp, [r4, #28]
    ldr     lr, [r4, #24]
    ldr     ip, [r4, #20]
    ldr     r3, [r4, #16]
    ldr     r2, [r4, #12]
    ldr     r1, [r4, #8]
    ldr     r0, [r4, #4]
    ldr     r4, [r4, #0]

    mov     pc, lr
    END
